<?php if (!defined('THINK_PATH')) exit(); /*a:1:{s:82:"F:\phpstudy_pro\WWW\www.danganguanli.com\public/../wcapps/admin\view\ad\index.html";i:1561690414;}*/ ?>
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>
            广告管理
        </title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="format-detection" content="telephone=no">
        <link href="/static/skin/nei.css" type="text/css" rel="stylesheet">
        <link rel="stylesheet" href="/static/skin/combo.select.css">
    </head>
</head>
<body onLoad="initPage(),ad()">
<div id="LoadingBar"><img src="/static/images/load.gif" /></div>
<div class="contaiter">
	<div class="shuaxin" onclick="location.reload()" title="刷新">&#xe614;</div>
	<div class="nei03">
    	<form action="/admin/ad/index" method="post">
            <div class="nei03_01">            	
                <div class="nei03_01_01">
                    选择分类：
                </div>
                <div class="nei03_01_02" style="width: 250px">
                    <select name="cid" id="cid">
                        <option value="">不启用</option>
                        <?php if(is_array($list) || $list instanceof \think\Collection || $list instanceof \think\Paginator): $i = 0; $__LIST__ = $list;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vo): $mod = ($i % 2 );++$i;?>
                        	<option value="<?php echo $vo['id']; ?>"  <?php if($cid == $vo['id']): ?> selected="selected" <?php endif; ?>><?php echo $vo['name']; ?></option>
                        <?php endforeach; endif; else: echo "" ;endif; ?>
                    </select>
                </div>
                <div class="nei03_01_03">
                    <input placeholder="输入关键词搜索" name="title" id="title" value="<?php echo $title; ?>" class="layui-input-2">
                </div>
                <div class="nei03_01_03">
                    <button type="submit" class="layui-input-3 layui-btn-green"><i class="layui-icon" style="font-size:18px;color:#FFF;">&#xe615;</i></button>
                </div>
                </div>
        </form>
        <div class="nei03_02 site-demo-button" style="margin-top: 20px;">
            <button class="layui-btn  layui-btn-1" onClick="openChuang('添加友链 ','<?php echo url('admin/ad/add'); ?>')">+ 添加广告 </button>
        </div>
    </div>
    <div class="nei02">
        <div class="nei02_01 l01">
            <div class="nei02_01_07">
            	<h3>
                	<i><label><input type="checkbox"  id="checkall" name="checkall"><tt>✓</tt></label></i>
                	<span class="s01">广告名称</span>
                	<span class="s04">广告位置</span>
                	<span class="s05">排序</span>
                	<span class="s04">URL</span>
                    <span class="s03"></span>
                </h3>
                <div class="nei02_01_07_01" id="list1">
                </div>
                <div class="nei02_01_04_02" id="pageDemo"></div>
            </div>
        </div>
    </div>
</div>
<input type="hidden" id="pages1" name="pages1" value="1">
<script src="/static/js/jquery-1.10.2.min.js" type="application/javascript"></script>
<script src="/static/js/neijqtab.js" type="application/javascript"></script>
<script src="/static/js/xlayui/layui.js" charset="utf-8"></script>
<script src="/static/js/jquery.combo.select.js"></script>
<script>
$(function() {
	$('select').comboSelect();
});
</script>
<script>
function initPage(){
	var objLoading = document.getElementById("LoadingBar");
	if (objLoading != null){
		objLoading.style.display = "none";
		$(".contaiter").css("display","block");
	}
}
</script>
<script>
layui.use(['form','laypage', 'layer'], function(){ //独立版的layer无需执行这一句
  var $ = layui.jquery,form = layui.form(),laypage = layui.laypage, layer = layui.layer; //独立版的layer无需执行这一句
});
function openChuang(title,url){
	 var othis = $(this), method = othis.data('method');
    //多窗口模式，层叠置顶
      layer.open({
        type: 2 //此处以iframe举例
        ,title: title
         ,area: ['100%', '100%']
        ,shade: 0
        ,maxmin: true
        ,offset: [ //为了演示，随机坐标
          $(window).height()-$(window).height()
          ,$(window).width()-$(window).width()
        ]
        ,content: url
      });
}
function pageNum(id,total,pages){
	layui.use('laypage', function(){ //独立版的layer无需执行这一句
	var laypage = layui.laypage; //独立版的layer无需执行这一句
	laypage({
		cont: id //分页容器的id
		,pages: total //总页数
		,skin: '#5FB878' //自定义选中色值
		,curr: pages //当前页
		,skip: true //开启跳页
		,jump: function(obj, first){
		if(!first){
			layer.msg('第'+ obj.curr +'页',{time:300});
			if(id=="pageDemo") ad(obj.curr);
		}
		}
		});
	});
}
function ad(pages){
	cid = $("#cid").val();
	proid = $("#proid").val();
	title = $("#title").val();
	$.ajax({
		type: "POST",
		async:false,
		contentType:"application/x-www-form-urlencoded; charset=UTF-8",
		url: "<?php echo url('admin/ad/lists'); ?>",
		data: {pagesize:9,pages:pages,cid:cid,proid:proid,title:title},
		error:function(msg){
			alert("错误");
		},
		success:function(msg){
			 json = msg.data;
			 var html="";
			 for(var i=0; i<json.length; i++)
			 {		
             
			  html += '<li><i><label><input type="checkbox" name="test" value="'+json[i].id+'"><tt>✓</tt></label></i><span class="s01">'+json[i].name+'</span><span class="s04">'+json[i].cname+'</span><span class="s05">'+json[i].vieworder+'</span><span class="s04">'+json[i].url+'</span><span class="s05"><tt class="t02" onClick=openChuang("编辑信息","/admin/ad/edit/id/'+json[i].id+'/")>编辑</tt></span><span class="s05"><tt class="t01" onclick=openDelete('+json[i].id+')>删除</tt></span></li>';
			 }
			$('#list1').html(html);
			pageNum('pageDemo',msg.totalpage,pages);
			if(pages>1)
			 	$("#pages1").val(msg.totalpage);
			else
				$("#pages1").val(1);
		}
	});
}
function openDelete(id){
	layer.confirm('确定要删除本条信息吗，删除无法恢复?', {icon: 3, title:'删除提示框'}, function(index){
		var loading2 = layer.load();
		$.ajax({
			url:"<?php echo url('admin/ad/delete'); ?>",
			type:"POST",
			data:{id:id},
			dataType:"",
			success:function(json){
				layer.close(loading2);
				if(json==1){
					layer.alert("删除成功!");
					ad($("#pages1").val());
				}else{
					layer.alert("删除失败",{time:1000});
				}
				layer.close(index);
			},
			error:function(res){
				alert('删除语句错误!');
			}
		});		return false;
	});
}
</script>
</body>
</html>